package com.uvlab.sitespot.common;

import org.json.JSONObject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Administrator on 2016/4/20.
 */
public class ToJson {
    public static JSONObject toJson(){
        Iterator it= ToJson.doc().iterator();
        JSONObject jsonObject=new JSONObject();
        List list=doc();
        while(it.hasNext()){
        if(list==null){
           jsonObject= jsonObject.accumulate("Test",it.next());
            return jsonObject;
        }else {
            jsonObject=jsonObject.accumulate("Test",it.next());
            return jsonObject;
        }
        }
        return null;
    }
    public static List doc(){
        List arrayList=new ArrayList();
        File f = new File("/");
        String suffix;
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        File[] files=f.listFiles();
        for(File file:files){
            String name=file.getName();
            Date lastModified = new Date(file.lastModified()); //文件最后修改时间
            String dataTimeStr = fmt.format(lastModified); //把它转化为yyyy-MM-dd HH:mm:ss形式
            suffix=name.substring(name.lastIndexOf(".")+1);
            if(file.isDirectory() &&( name.startsWith(".")||name.equals(suffix))){
                suffix="null";
            }
            /*Files file1 =new Files(name,suffix,file.length(),dataTimeStr);
            arrayList.add(file1);*/
        }
        return arrayList;
    }
}
